import maya.cmds as cmds
cmds.SelectAll();
cmds.Delete();

height = 43.0
circleDiameter = 120
motorDiameter = 82.5
baseThickness = 2#area that is square
topCylinderHeight = 6;
cubeSide = 120
wallThickness = 4
screwHoleDiameter = 5.0
strutRadius = 20
ventDiameter = 30.0
holeDistance = 105#refers to x/y not diagonal 

def createVerticalHole( x, z, radius, object):
    hole = cmds.polyCylinder(sa=100,r=radius,h=height*2.0)#polypipe bug, where height is created at half height. :(
    cmds.move(x,0,z);
    cmds.select(object[0],hole[0]);
    return cmds.polyBoolOp(op=2);

def createStruts(degrees,object):
    for i in xrange(0,360,degrees):
        hole = cmds.polyCylinder(sa=100,r=strutRadius,h=height*2.0)#polypipe bug, where height is created at half height. :(
        cmds.select(object[0],hole[0]);
        cmds.align(y='min',alignToLead=True);
        cmds.select(hole[0]);
        cmds.move(motorDiameter/2.0+strutRadius+wallThickness,baseThickness,0,relative=True);
        cmds.rotate(0,i,0,p=(0,0,0));#rotate about origin
        cmds.select(object[0],hole[0]);
        object = cmds.polyBoolOp(op=2);
    return object;
    
def createPartialCone(radius1,radius2,height):
    coneHeight = (radius2*height/(radius1-radius2)) + height;
    cutterCone = cmds.polyCone(sx=20,sy=30,sz=10,r=radius1,height=coneHeight);
    cutterBox = cmds.polyCube(w=radius1*2.0+wallThickness, h=height,sy=5,d=radius1*2.0+wallThickness);#will be used to cut cone to size
    cmds.select(cutterBox[0],cutterCone[0]);
    cmds.align(y='min',alignToLead=True);
    returnObject = cmds.polyBoolOp(op=3);
    cmds.xform(cp=True);
    cmds.move(0,0,0,ws=True,rpr=True);    
    return returnObject;

def createPartialHollowCone(radius1,radius2,height,thickness):
    outterCone = createPartialCone(radius1+thickness,radius2+thickness,height);
    innerCone = createPartialCone(radius1,radius2,height);
    cmds.select(outterCone[0],innerCone[0]);
    cmds.align(y='min',alignToLead=True);
    returnObject = cmds.polyBoolOp(op=2); 
    cmds.xform(cp=True);
    cmds.move(0,0,0,ws=True,rpr=True);
    return returnObject; 
    

def createSideHole(object,size,rotation,position):
    hole  = cmds.polyCylinder(sa=100,r=size,h=motorDiameter+wallThickness*2)
    cmds.rotate('90deg',rotation,0);
    cmds.select(object[0],hole[0]);
    cmds.align(y='Max',alignToLead=True);
    cmds.select(hole[0]);
    cmds.move(0,position,0,relative=True);
    cmds.select(object[0],hole[0]);
    returnObject =cmds.polyBoolOp(object[0],hole[0],op=2); 
    return returnObject;

def createVentHole(object,size,rotation):
    hole  = cmds.polyCylinder(sa=100,r=size,h=height*10.0)#polypipe bug, where height is created at half height. :(
    cmds.rotate('90deg',rotation,0);
    cmds.select(object[0],hole[0]);
    cmds.align(y='mid',alignToLead=True);
    cmds.select(hole[0]);
    cmds.select(object[0],hole[0]);
    return cmds.polyBoolOp(op=2);



box = cmds.polyCube(w=cubeSide+wallThickness*2, h=baseThickness,sy=5,d=cubeSide+wallThickness*2)
#innerCircle = cmds.polyCylinder(sa=100,r=circleDiameter/2.0,h=height)#polypipe bug, where height is created at half height. :(
outterCone = createPartialCone(circleDiameter/2.0+wallThickness,motorDiameter/2.0+wallThickness,height)
innerCone = createPartialCone(circleDiameter/2.0,motorDiameter/2.0,height)

cmds.select(box[0]);
cmds.select(box[0],outterCone[0]);#can't figure out why this is the proper order
cmds.align(y='min',alignToLead=True);
shroudOutter = cmds.polyBoolOp(op=1);
cmds.select(shroudOutter[0],innerCone[0]);
shroudOutter = cmds.polyBoolOp(op=2);

shroudOutter = createVerticalHole(holeDistance/2.0,holeDistance/2.0,screwHoleDiameter/2.0,shroudOutter);
shroudOutter = createVerticalHole(holeDistance/2.0,-holeDistance/2.0,screwHoleDiameter/2.0,shroudOutter);
shroudOutter = createVerticalHole(-holeDistance/2.0,holeDistance/2.0,screwHoleDiameter/2.0,shroudOutter);
shroudOutter = createVerticalHole(-holeDistance/2.0,-holeDistance/2.0,screwHoleDiameter/2.0,shroudOutter);

shroudOutter = createStruts(45,shroudOutter);

top = cmds.polyPipe(sa=100,r=motorDiameter/2.0+wallThickness,h=topCylinderHeight*2.0,t=wallThickness)#polypipe bug, where height is created at half height. :(
cmds.select(shroudOutter[0],top[0]);#can't figure out why this is the proper order
cmds.align(y='max',alignToLead=True);
cmds.select(top[0]);
cmds.move(0,topCylinderHeight,0,relative=True);
cmds.select(shroudOutter[0],top[0]);#can't figure out why this is the proper order
shroudOutter = cmds.polyBoolOp(op=1);
shroudOutter = createSideHole(shroudOutter,screwHoleDiameter/2.0,-30,-2.0);
cmds.rotate('90deg',0,0);



